package com.shimao.celnet.payment.quartz;

import org.quartz.*;
import org.springframework.stereotype.Service;

@Service
public class QuartzEventService  {


    /**
     * 定时推送汇总支付
     * 凌晨5点推送---立方停车系统是每天凌晨2:30推送。所以要晚于这个时间点
     */
    public static final String QUARTZ_GROUP_01 = "group01";
    public static final String QUARTZ_JOB_01 = "job01";
    public static final String QUARTZ_TRIGGER_01 = "trigger01";
    public static final String QUARTZ_RATE_01 = "0 0 5 * * ?";//秒 分 时 日 月 年
    /**
     * 定时推送收费系统失败的发票
     * 每一个小时，推送一次
     */
    public static final String QUARTZ_GROUP_02 = "group02";
    public static final String QUARTZ_JOB_02 = "job02";
    public static final String QUARTZ_TRIGGER_02 = "trigger02";
    public static final String QUARTZ_RATE_02 = "0 10 0/1 * * ?";//秒 分 时 日 月 年
    /**
     * 定时推送收费系统失败的发票
     * 定时定点触发一次工作任务
     */
    public static final String QUARTZ_GROUP_03 = "group03";
    public static final String QUARTZ_JOB_03 = "job03";
    public static final String QUARTZ_TRIGGER_03 = "trigger03";
    public static final String QUARTZ_RATE_03 = "0 0/15 * 18 9 ? 2018";//秒 分 时 日 月 周 年

    /**
     * 定时解析more+通联账目文件
     * 凌晨5点45解析---通联每天五点之后才能查询前一日账目
     */
    public static final String QUARTZ_GROUP_04 = "group04";
    public static final String QUARTZ_JOB_04 = "job04";
    public static final String QUARTZ_TRIGGER_04 = "trigger04";
    public static final String QUARTZ_RATE_04 = "0 45 5 * * ?";//秒 分 时 日 月 年


    public void addQuartz01(Scheduler scheduler) throws SchedulerException {

        JobDetail job = JobBuilder.newJob(payParkDaySumInfoPush.class).withIdentity(QUARTZ_JOB_01, QUARTZ_GROUP_01).build();
        CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(QUARTZ_RATE_01);
        Trigger trigger = TriggerBuilder.newTrigger().withIdentity(QUARTZ_TRIGGER_01, QUARTZ_GROUP_01).withSchedule(scheduleBuilder).build();
        scheduler.scheduleJob(job, trigger);
    }

    public void addQuartz02(Scheduler scheduler) throws SchedulerException {

        JobDetail job = JobBuilder.newJob(FailInvoicePushAgain.class).withIdentity(QUARTZ_JOB_02, QUARTZ_GROUP_02).build();
        CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(QUARTZ_RATE_02);
        Trigger trigger = TriggerBuilder.newTrigger().withIdentity(QUARTZ_TRIGGER_02, QUARTZ_GROUP_02).withSchedule(scheduleBuilder).build();
        scheduler.scheduleJob(job, trigger);
    }

    public void addQuartz03(Scheduler scheduler) throws SchedulerException {

        JobDetail job = JobBuilder.newJob(EInvoicePush.class).withIdentity(QUARTZ_JOB_03, QUARTZ_GROUP_03).build();
        CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(QUARTZ_RATE_03);
        Trigger trigger = TriggerBuilder.newTrigger().withIdentity(QUARTZ_TRIGGER_03, QUARTZ_GROUP_03).withSchedule(scheduleBuilder).build();
        scheduler.scheduleJob(job, trigger);
    }

    public void addQuartz04(Scheduler scheduler) throws SchedulerException {

        JobDetail job = JobBuilder.newJob(GetTLPayRecord.class).withIdentity(QUARTZ_JOB_04, QUARTZ_GROUP_04).build();
        CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(QUARTZ_RATE_04);
        Trigger trigger = TriggerBuilder.newTrigger().withIdentity(QUARTZ_TRIGGER_04, QUARTZ_GROUP_04).withSchedule(scheduleBuilder).build();
        scheduler.scheduleJob(job, trigger);
    }
}
